home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / ICON_8 / ICONX_FO / LREC.C < prev    next >
Text File  |  1990-03-02  |  2KB  |  110 lines

  1. /*
  2.  * File: lrec.c
  3.  *  Contents: field, mkrec
  4.  */
  5.  
  6. #include "::h:config.h"
  7. #include "::h:rt.h"
  8. #include "rproto.h"
  9.  
  10. #ifdef PreProcess
  11. /* include(../M4/lib.m4) /* */
  12. /* */
  13. #endif                    /* PreProcess */
  14.  
  15. /*
  16.  * x.y - access field y of record x.
  17.  */
  18.  
  19. LibDcl(field,2,".")
  20.    {
  21.    register word fnum;
  22.    register struct b_record *rp;
  23.    register dptr dp;
  24.    extern word *ftabp, *records;
  25.  
  26. #if MACINTOSH
  27. #if MPW
  28. /* #pragma unused(nargs) */
  29. #endif                    /* MPW */
  30. #endif                    /* MACINTOSH */
  31.  
  32.    if (DeRef(Arg1) == Error) 
  33.       RunErr(0, NULL);
  34.  
  35.    /*
  36.     * Arg1 must be a record and Arg2 must be a field number.
  37.     */
  38.    if (Arg1.dword != D_Record) 
  39.       RunErr(107, &Arg1);
  40.  
  41.    /*
  42.     * Map the field number into a field number for the record x.
  43.     */
  44.    rp = (struct b_record *) BlkLoc(Arg1);
  45.    fnum = ftabp[IntVal(Arg2) * *records + rp->recdesc->proc.recnum - 1];
  46.    /*
  47.     * If fnum < 0, x doesn't contain the specified field.
  48.     */
  49.    if (fnum < 0) 
  50.       RunErr(207, &Arg1);
  51.  
  52.    /*
  53.     * Return a pointer to the descriptor for the appropriate field.
  54.     */
  55.    dp = &rp->fields[fnum];
  56.    Arg0.dword = D_Var + ((word *)dp - (word *)rp);
  57.    VarLoc(Arg0) = (dptr)rp;
  58.    Return;
  59.    }
  60.  
  61.  
  62. /*
  63.  * mkrec - create a record.
  64.  */
  65.  
  66. LibDcl(mkrec,-1,"mkrec")
  67.    {
  68.    register int i;
  69.    register struct b_proc *bp;
  70.    register struct b_record *rp;
  71.  
  72.    /*
  73.     * Be sure that call is from a procedure.
  74.     */
  75.  
  76.    /*
  77.     * Ensure space for the record to be created.
  78.     */
  79.    if (blkreq((uword)sizeof(struct b_record) +
  80.          BlkLoc(Arg(0))->proc.nfields*sizeof(struct descrip)) == Error) 
  81.       RunErr(0, NULL);
  82.  
  83.    /*
  84.     * Get a pointer to the record constructor procedure and allocate
  85.     *  a record with the appropriate number of fields.
  86.     */
  87.    bp = (struct b_proc *) BlkLoc(Arg(0));
  88.    rp = alcrecd((int)bp->nfields, (union block **)bp);
  89.    rp->id = (bp->recid)++;
  90.  
  91.    /*
  92.     * Set all fields in the new record to null value.
  93.     */
  94.    for (i = (int)bp->nfields; i > nargs; i--)
  95.       rp->fields[i-1] = nulldesc;
  96.  
  97.    /*
  98.     * Assign each argument value to a record element and dereference it.
  99.     */
  100.    for ( ; i > 0; i--) {
  101.       rp->fields[i-1] = Arg(i);
  102.       if (DeRef(rp->fields[i-1]) == Error) 
  103.          RunErr(0, NULL);
  104.       }
  105.  
  106.    ArgType(0) = D_Record;
  107.    Arg(0).vword.bptr = (union block *)rp;
  108.    Return;
  109.    }
  110.